import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome(executable_path='Chromedriver.exe')
driver.get("https://hmshop-test.itheima.net/")
# 放大浏览器页面
driver.maximize_window()
# 通过超链接定位页面元素，打开登录界面
driver.find_element_by_partial_link_text("登录").click()
# 暂停3秒
time.sleep(3)
# 通过id来进行定位，输入18776895770
driver.find_element_by_id("username").send_keys("18776895770")
# 通过name来进行定位，输入q2431521637
driver.find_element_by_name("password").send_keys("q2431521637")
# 通过xpath来定位，输入8888
driver.find_element_by_xpath("//input[@id='verify_code']").send_keys("8888")
# 通过css属性元素来定位，点击登录按钮
driver.find_element_by_css_selector("[name='sbtbutton']").click()
# # 1). 手动登录TP，获取cookie
# # 1. 登录TP，登录成功后抓取 (PHPSESSID)
# # 2. 使用add_cookie()方法，添加 (PHPSESSID)键和值
driver.add_cookie({"name": "PHPSESSID", "value": "ogo0o63aldgn9j4o83jefniko3"})
# 获取所有cookie
cookies = driver.get_cookies()
print("cookies内容为:", cookies)
for co in cookies:
    print(co['name'])
# 3. 调用刷新方法 driver.refresh()
driver.refresh()






